package com.helsinki.controller;

import com.github.pagehelper.PageInfo;
import com.helsinki.pojo.Orders;
import com.helsinki.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Map;

@RestController
@RequestMapping("/orders")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    @RequestMapping("/findById")
    public Orders findById(String id) {
        return ordersService.queryById(id);
    }

    @RequestMapping("list")
    @ResponseBody
    public PageInfo<Orders> list(Model model,
                                  @RequestParam(defaultValue = "1") Integer pageNum,
                                  @RequestParam(defaultValue = "10") Integer pageSize) {
        return ordersService.queryAll(pageNum,pageSize);
    }


    @RequestMapping(value = "/updateStatus",method = RequestMethod.POST)
    @ResponseBody
    public String updateStatus(@RequestBody Map<String,Object> map){
        ArrayList arr = (ArrayList) map.get("ids");
        String[] ids = (String[]) arr.toArray(new String[0]);
        int status = (int) map.get("status");

        ordersService.updateStatus(ids,status);
        return null;
    }
    @RequestMapping("/update")
    public String update(@RequestBody Orders order) {

        // 断点调试可发现order中的时间可以正常接收
        return "";
    }
}